summaryrefslogtreecommitdiffstats
path: root/docusaurus/static/ajax/libs/wolfree/23.7.8/js/AJAX.js
blob: 465787d05e4e53fd9282de0617de2142fff4df92 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
 * @license
 * SPDX-License-Identifier: AGPL-3.0-or-later
 * This file is part of Wolfree.
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 */

// @ts-check

import SearchParams from "./SearchParams.js";

export default class AJAX {
  ajax = async ({
    input = String(),
    i2d = Boolean(),
    extraPodstates = Array(),
  } = {}) => {
    try {
      const data = new SearchParams().getSearchParams({
        input,
        extraPodstates,
        i2d,
      });

      const options = {
        url: "https://api.wolframalpha.com/v2/query",
        dataType: "jsonp",
        traditional: true,
        data,
      };

      try {
        /**
         * https://www.npmjs.com/package/@types/jquery
         * @type {import('jQuery')}
         */
        const response = await jQuery.ajax(options);
        return (
          console.assert(response instanceof Object),
          console.assert(response.hasOwnProperty("queryresult")),
          { response }
        );
      } catch (error) {
        return (
          console.error(
            { error },
            "We encountered an issue while attempting to retrieve a response from the Wolfram Alpha API using the jQuery library."
          ),
          { error }
        );
      }
    } catch (error) {
      return console.error({ error }), { error };
    }
  };
}